import { Prisma } from '@prisma/client';
import { prisma } from './prisma-client';
import { hashSync } from 'bcrypt';
import { dataCategories, _dataExtraCategory} from './constants';

// генерация
async function up() {
  await prisma.user.createMany({
    data: [
      {
        fullName: 'User1',
        email: '11@mail.ru',
        password: hashSync('qwrty', 10),
        verified: new Date(),
        role: 'USER',
      },
      {
        fullName: 'User2',
        email: '22@mail.ru',
        password: hashSync('qwrty123', 10),
        verified: new Date(),
        role: 'USER',
      },
      {
        fullName: 'Admin1',
        email: 'admin22@mail.ru',
        password: hashSync('qwArty123', 10),
        verified: new Date(),
        role: 'ADMIN',
      },
    ],
  });

  await prisma.category.createMany({
    data: dataCategories,
  });

  await prisma.extraCategory.createMany({
    data: _dataExtraCategory,
  });

}

// очистка
async function down() {
  await prisma.$executeRaw`TRUNCATE TABLE "User" RESTART IDENTITY CASCADE`;

}
async function main() {
  try {
    await down()
    await up()

  } catch (e) {
    console.log(e)
  }
}

main()
  .then(async () => {
    await prisma.$disconnect();
  })
  .catch(async (e) => {
    console.error(e);
    await prisma.$disconnect();
    process.exit(1);
  });